package com.hdax.dm.scheduler.mapstruct;

import com.hdax.dm.entity.scheduler.SchedulerSeatPrice;
import com.hdax.dm.scheduler.dto.ChooseSeatScheduleDto;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.List;

@Mapper(componentModel = "spring")
public abstract class SeatPriceDtoMapper {

    /**
     * 转换
     * @param areaLevel
     * @return
     */
    protected String turnToString(Long areaLevel){
        if(areaLevel == 1) return "A";
        if(areaLevel == 2) return "B";
        if(areaLevel == 3) return "C";
        return null;
    }

    protected Integer turnToInteger(Double price){
        return price.intValue();
    }

    @Mappings(
            value = {
                    //java代码表达式 expression                                          实参
                    //内部转换,并且赋值
                    @Mapping(target = "areaLevelName", expression = "java(turnToString(source.getAreaLevel()))"),
                    @Mapping(target = "price",expression = "java(turnToInteger(source.getPrice()))")
            }
    )
    public abstract ChooseSeatScheduleDto.SeatPrice toTarget(SchedulerSeatPrice source);
    public abstract List<ChooseSeatScheduleDto.SeatPrice> toTargetList(List<SchedulerSeatPrice> sources);
}